package com.project.internship.controller.evaluate;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.internship.entity.StudentEvaluate;
import com.project.internship.entity.resp.RespBean;
import com.project.internship.entity.resp.RespPageBean;
import com.project.internship.service.StudentEvaluateService;
import com.project.internship.vo.StudentEvaluateVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 教师端学生评价
 */
@RestController
@RequestMapping("/evaluate/student")
public class EvaStudentController {

    @Autowired
    StudentEvaluateService seService;

    /**
     * 获取学生评价信息
     * 根据学号查询单条信息
     * @param current
     * @param size
     * @param keyword
     * @return
     */
    @GetMapping("/")
    public RespPageBean getStudentEva(@RequestParam(defaultValue = "1") Integer current,
                                       @RequestParam(defaultValue = "10") Integer size,
                                       String keyword){
        Page<StudentEvaluateVO> page = new Page<>(current,size);

        Long total = seService.getStudentEva(page,keyword).getTotal();
        List<StudentEvaluateVO> data =  seService.getStudentEva(page,keyword).getRecords();

        return new RespPageBean(total,data);
    }

    /**
     * 添加学生评价
     * @param studentEva
     * @return
     */
    @PostMapping("/")
    public RespBean addStudentEva(@RequestBody StudentEvaluate studentEva){
        if(seService.addStudentEva(studentEva) == 1){
            return RespBean.ok("添加成功！");
        }
        return RespBean.error("添加失败！");
    }

    /**
     * 修改学生评价
     * @param studentEva
     * @return
     */
    @PutMapping("/")
    public RespBean updateStudentEva(@RequestBody StudentEvaluate studentEva){
        if(seService.updateStudentEva(studentEva) == 1){
            return RespBean.ok("更新成功！");
        }
        return RespBean.error("更新失败！");
    }


}
